package org.jeecg.modules.bpm.dto;

import java.util.Date;

import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;

import io.swagger.annotations.Api;
import lombok.Data;

@Data
@Api(tags="流程任务")
public class TaskDTO implements java.io.Serializable {
	private static final long serialVersionUID = 1L;
	private String id;
	/** 任务名*/
	private String taskName;
	/** 任务ID*/
	private String taskId;
	/** 任务办理人 - 用户名*/
	private String taskAssigneeName;
	/** 任务办理人 - 用户ID*/
	private String taskAssigneeId;
	/** 任务开始时间*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date taskBeginTime;
	/** 任务结束时间*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date taskEndTime;
	/** 任务耗时*/
	private Long taskDueTime;
	
	/** 流程发起人，用户名*/
	private String processApplyUserName;
	/** 流程发起人，用户ID*/
	private String processApplyUserId;
	/** 流程编号*/
	private String processDefinitionId;
	/** 流程名称*/
	private String processDefinitionName;
	/** 流程实例ID*/
	private String processInstanceId;
	
	
	
	/** 业务标题*/
	private String bpmBizTitle;
	/** 流程状态 未发起、处理中、处理完成*/
	private String bpmStatus;
	/** 超时提醒*/
	private Boolean taskTimeoutWarn;
	/** 是否催办*/
	private Boolean taskUrge;
	/** 催办说明*/
	private String taskUrgeRemark;
	
	/** 意见*/
	private String remarks;
	/**
	* 时间的处理
	* @param time
	* @return
	*/
	public  String dealTimeFromNum(long time) {
		StringBuilder result = new StringBuilder();
		long interval = time / 1000;
		final long day = 24 * 60 * 60;
		final long hour = 60 * 60;
		final long minute = 60;
		int detailDay = 0;
		int detailHour = 0;
		int detailMinute = 0;
		int detailSecond = 0;
		if (interval >= day) {
			detailDay = (int) (interval / day);
			interval = interval - detailDay * day;
		}
		if (interval >= hour) {
			detailHour = (int) (interval / hour);
			interval = interval - hour * detailHour;
		}
		if (interval >= minute) {
			detailMinute = (int) (interval / minute);
			interval = interval - detailMinute * minute;
		}
		if (interval > 0) {
			detailSecond = (int) interval;
		}
		result.setLength(0);
		if (detailDay > 0) {
			result.append(detailDay);
			result.append("天");
		}
		if (detailHour > 0) {
			result.append(detailHour);
			result.append("小时");
		}
		if (detailMinute > 0) {
			result.append(detailMinute);
			result.append("分");
		}
		if (detailSecond > 0) {
			result.append(detailSecond);
			result.append("秒");
		}
		return result.toString();
	}

	public String getDurationStr(){
		try {
			if(this.taskDueTime == null) {
				return null;
			}
			return dealTimeFromNum(this.taskDueTime);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
}

	